﻿/*
  import com._public._text.TextCircling;

	var content_mc:Sprite = new Sprite();
	addChild(content_mc);
	content_mc.x=stage.stageWidth/2;
	content_mc.y=stage.stageHeight;

	TextCircling.getInstance().textCircling("878096878878096878096",content_mc);
*/
package com._public._text
{
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.TextField;
	import flash.utils.Timer;
	/**
	 * ...
	 * @lbynet 
	 */
	public class TextCircling 
	{
		
		private static var Instance:TextCircling = new TextCircling();
		private var text_string:String;
		private var content_mc:DisplayObjectContainer;
		
		private var newX:Number;
		private var newY:Number;
		private var W:Number;
		
		private var i:uint;
		
		private var timer:Timer;
		private var totalNum:uint;	
		private var index:uint;
		private var dis:Number = -200;
		public function TextCircling() 
		{
			
		}
		
		public static function getInstance():TextCircling {
			
			return Instance;
		}
		
		public function textCircling(_string:String, content:DisplayObjectContainer):void {
			
			this.text_string = _string;
			
			this.content_mc = content;
			this.removeAllItem(this.content_mc);
			
			init();
		}
		
		private function init():void {
			
			this.totalNum = this.text_string.length;
			this.i = 0;
			
			this.addListener();
		}
		private function addListener():void {
			
			this.timer = new Timer(500);
            this.timer.addEventListener(TimerEvent.TIMER, timerHandler);
			this.timer.start();
		}
		private function timerHandler(event:TimerEvent):void {
			
            if (this.index < this.totalNum) {
				
				var temp1:String = this.text_string.substring(this.index, this.index+1);
				var _txt:MoveText = new MoveText();
				_txt.text = temp1;
				this.content_mc.addChild(_txt);
				
				_txt.width = _txt.textWidth + 10;
				_txt.height = _txt.textHeight + 10;
				
				_txt.addEventListener(Event.ENTER_FRAME, RemoveDrop);
				
				this.index ++;
            } else {
				
				this.index = 0;
                this.timer.removeEventListener(TimerEvent.TIMER, timerHandler);
            }
		}
		
		
		private function RemoveDrop(event:Event):void {
			var _txt:MoveText = event.target as MoveText;
			
			if (_txt.scaleX <= 0) {
				_txt.removeEventListener(Event.ENTER_FRAME, RemoveDrop);
				this.content_mc.removeChild(_txt);
			}
		}
		
		/*
		 * 
		 * @移除所有项
		*/
		public function removeAllItem(content_mc:DisplayObjectContainer):void {
			
			var count:int = content_mc.numChildren;
			for (var i:int = 0; i < count; i++) {
				content_mc.removeChildAt(0);
			}
		}
		
	}
	
}

import flash.text.TextField;
	import flash.events.Event;
	/**
	 * ...
	 * @author lbynet (随机抛出数字)
	 */
	class MoveText extends TextField
	{
		
		private var dis:Number;
		
		public function MoveText() 
		{
			
			//this.cacheAsBitmap = true;
			//this.mouseEnabled = false;
			
			init();
		}
		private function init():void
		{
			
			this.scaleX = this.scaleY = 2 + Math.random();
			//产生随机数-5到5之间的随机数
			dis = Math.round((Math.random() - .5) * 10)/5;
			this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
		}
		private var dim:Number = 0.1;
		private function enterFrameHandler(event:Event):void 
		{
			dim += 0.05;
			this.y -= 5*Math.sin(dim);
			this.x += dis;
			
			this.scaleX -=.02;
			this.scaleY -=.02;
		}
		
		public function Dis():Number
		{
			return this.dis;
		}
		
	}